<template>
  <div>
    <van-nav-bar class="page-nav-bar" title="账号登录" left-text="" left-arrow  @click-left="onClickLeft"/>

    <van-form  @submit="onSubmit">
      <van-field
        v-model="form.username"
        placeholder="请输入账号"
        :rules="[{ required: true, message: '请填写账号' }]"
      />
      <van-field
        v-model="form.password"
        type="password"
        placeholder="请输入密码"
        :rules="[{ required: true, message: '请填写密码'}]"
      />
      <div style="margin: 16px">
        <van-button round block type="info" native-type="submit" color="rgb(33, 185, 122)"
          >登录</van-button
        >
      </div>
    </van-form>
  </div>
</template>

<script>
import axios from 'axios'
axios.defaults.baseURL = 'http://liufusong.top:8080/'
export default {
  name: 'login',
  data () {
    return {
      form: {
        username: '',
        password: ''
      }
    }
  },

  created () {
  },

  methods: {
    onClickLeft () {
      this.$router.back()
    },
    async  onSubmit () {
      try {
        const res = await axios({
          url: 'user/login',
          method: 'POST',
          data: this.form
        })
        console.log(res.status)
        if (res.status === 200) {
          alert('22222')
          this.$router.push('/layout/home')
        }
      } catch (error) {
        alert(error)
      }
    }
  }
}
</script>

<style scoped lang="less">
.page-nav-bar {
  background-color: rgb(33, 185, 122);
}
/deep/.van-nav-bar__text {
  color: #fff;
}
/deep/.van-nav-bar__title {
  color: #fff;
}
/deep/.van-nav-bar__content{
background-color: rgb(33, 185, 122);
}
/deep/.van-nav-bar__title{
  color: #fff;

}
/deep/.van-nav-bar .van-icon{
  color: #fff;

}
</style>
